<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        

        const $ = {};
        $.get = function(url, params, fn,type){
            const xhr = new XMLHttpRequest();
            let str = '';
            if(typeof params === 'object'){
                for(let attr in params){
                    str += `${attr}=${params[attr]}&`;
                }
                str = str.slice(0,-1);
                console.log(str);
            }
            url = url + '?' + str;
            xhr.open('GET',url);
            if(typeof type === 'string'){
                xhr.responseType = type;
            }
            xhr.send();
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4){
                    if(xhr.status >=200 && xhr.status < 300){
                        fn(xhr.response);
                    }
                }
            }
        }
        $.get('http://127.0.0.1/json',{name:'atguigu',age:10},function(data){
            console.log(data);
        },'json');
    </script>
</body>
</html>